/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.game.math.view.render;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import org.game.math.view.domain.Examination;
import org.game.math.view.domain.ExpressionTableModel;
import org.game.math.view.domain.MathExpression;

/**
 *
 * @author nmduc
 */
public class ExpressionCellRenderer extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        TableModel model = table.getModel();
        if (model instanceof ExpressionTableModel) {
            Examination examination = ((ExpressionTableModel) model).getExamination();
            MathExpression expression = examination.getExpressionList().get(row);
            if (expression.isCorrected() != null && !expression.isCorrected()) {
                component.setForeground(Color.red);
            } else {
                if (!isSelected) {
                    component.setForeground(Color.black);
                } else {
                    component.setForeground(Color.white);
                }
            }
        }
        return component;

    }
}
